﻿using System;
using System.Web;

namespace Hourglass.Qrobot.Utils
{
    public static class CommonUtils
    {
        /// <summary>
        /// 排除x=的前缀进行UrlEncoding，然后再加上x=的前缀进行返回
        /// </summary>
        /// <param name="paras"></param>
        /// <returns></returns>
        public static string ParaEncodingWithoutStart(string paras)
        {
            int equalIndex;
            try
            {
                equalIndex = paras.IndexOf("=", StringComparison.Ordinal);
            }
            catch (Exception)
            {
                equalIndex = -1;
            }
            if (equalIndex != -1)
            {
                equalIndex += 1;
                var equalPrefix = paras.Substring(0, equalIndex);
                var paraContext = HttpUtility.UrlEncode(paras.Substring(equalIndex));
                paras = equalPrefix + paraContext;
            }
            return paras;
        }
    }
}
